#define checkpos(x, y) (0<=x&&x<m&&0<=y&&y<n)
class Solution {
public:
    const int d[4][2]={{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
    
    int countUnguarded(int m, int n, vector<vector<int>>& guards, vector<vector<int>>& walls) {
        vector guarded(m, vector<int8_t>(n));

        for(auto &g:guards) guarded[g[0]][g[1]]=-1; //敬畏格子
        for(auto &w:walls) guarded[w[0]][w[1]]=-1; //敬畏格子

        for(auto &g:guards) {
            for(auto &[dx, dy]:d) {
                int nx=g[0]+dx, ny=g[1]+dy;
                while(checkpos(nx, ny)&&guarded[nx][ny]!=-1)
                {
                    guarded[nx][ny]=1; //保卫
                    nx+=dx, ny+=dy;
                }
            }
        }
        int ans=0;
        for(auto &row:guarded) ans+=ranges::count(row, 0);
        return ans;
    }
};